package com.medication.model;

import java.util.List;

import com.beust.jcommander.internal.Lists;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;
import com.medication.utils.StringUtils;

/**
 * @author heem
 * @create time 创建时间：2017年3月29日 下午4:26:35
 * @version 1.0
 * @since
 */
@SuppressWarnings("serial")
public class LimitMedication extends Model<LimitMedication> implements com.medication.utils.ExcelExporter.Cellable {
	public static LimitMedication dao = new LimitMedication();

	public Page<LimitMedication> query(int pageNumber, String code, String name) {
		String select = "";
		StringBuilder from = new StringBuilder(" from limit_medication t where 1=1 ");
		List<Object> params = Lists.newArrayList();
		if (!StringUtils.isEmpty(code)) {
			from.append(" and t.code like ?");
			params.add("%" + code + "%");
		}
		if (!StringUtils.isEmpty(name)) {
			from.append(" and t.name like ?");
			params.add("%" + name + "%");
		}
		from.append(" order by code");
		return dao.paginate(pageNumber, 20, select, from.toString(), params.toArray());
	}

	@Override
	public String[] getCellValues() {
		List<String > values = Lists.newArrayList();
		values.add(getStr("category"));
		values.add(getStr("code"));
		values.add(getStr("name"));
		values.add(getStr("type"));
		values.add(getStr("reagentType"));
		values.add(getStr("limit"));
		values.add(getStr("remark"));
		return values.toArray(new String[]{});
	}

}
